<%--
  Created by IntelliJ IDEA.
  User: tianyu
  Date: 2023/7/10
  Time: 15:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>个人中心</title>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->

    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <link rel="stylesheet" href="./css/fileinput.min.css">

    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>
    <!-- jsp= html + servlet -->
    <script src="./js/fileinput.min.js"></script>

    <style>
        th,td{ text-align: center}
       /* .navbar {
            font-size: 25px;
            background-color: #2e317c;
        }*/
        .a {
            position: absolute;
            left: 42%;
            top: 30%;
            width: 250px;
            height: 225px;
            border: 1px solid darkgreen;
            bord-radius: 10px;
            background: aliceblue;
            text-align: center;
        }
    </style>

</head>

<body>
<!-- 导航  开始 -->
<div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">商品购物管理</a>
                </div>
                <div>
                    <%--<br><br>--%>
                    <!--向左对齐-->
                    <ul class="nav navbar-nav navbar-left">
                        <li class="dropdown">
                            <a href="home2.jsp" class="dropdown-toggle" ><%--data-toggle="dropdown"--%>
                                首页
                                <%--<b class="caret"></b>--%>
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="shopping2.jsp" class="dropdown-toggle" >商品</a>
                        </li>
                        <li class="dropdown">
                            <a href="myorder.jsp" class="dropdown-toggle" >我的订单</a>
                        </li>
                        <li class="dropdown">
                            <a href="Person.jsp" class="dropdown-toggle">
                                个人中心
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="/Test/buyerlogout" class="dropdown-toggle">
                                退出
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="login.html" class="dropdown-toggle" >后台管理</a> <%--data-toggle="dropdown"--%>
                        </li>
                    </ul>
                    <!--向右对齐 -->
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="shopcar.jsp" class="dropdown-toggle">
                                <img  src="./images/GWC.jpg" style="width: 50px; height: 50px;" alt="Logo">
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle">
                        <li class="dropdown"><%=session.getAttribute("buyername")%></li>
                        </a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div class="col-md-1"></div>
</div>
<!-- 导航  结束 -->

<div class="a">
    <h1>个人中心</h1>
    账号：<input type="text" id="buyername" ><br><%--style="margin-bottom: 4px;"--%>
    密码：<input type="password" id="password" ><br>
    电话：<input type="text" id="buyernum" ><br>
    地址：<input type="text" id="buyerplace"><br>

    <!--按钮-->
    <input type="button" value="修改" id="btn" onclick="updateOrders()">
    <input type="button" value="退出" id="btn2"><br>
</div>

</body>

<script src="./js/upload.js"></script>
<script>
    var name=<%=session.getAttribute("buyername")%>;
    getBuyer(name);
    function getBuyer(name)
    {
        $.ajax
        (
            {
                url: "/Test/buyer?method=getBuyerByName",//请求路径
                data: {buyername:name},//请求数据
                type: "GET",//请求方式 GET/POST/ PUT/DELETE
                //dataType: "json",//请求数据类型
                //contentType: "application/json",//返回数据类型
                success: function (data) {
                    console.log(data);
                    data = JSON.parse(data);//把后台的数据处理为json格式
                    if (data.code == "0000") {

                        $("#buyername").val(data.data.buyername);
                        $("#password").val(data.data.password);
                        $("#buyernum").val(data.data.buyernum);
                        $("#buyerplace").val(data.data.buyerplace);
                    } else {
                        alert("查询失败！");
                    }
                }
            }
        )

    }

    function updateOrders() {
        var id=<%=session.getAttribute("id")%>;
        var buyername = $("#buyername").val();
        var password = $("#password").val();
        var buyernum = $("#buyernum").val();
        var buyerplace = $("#buyerplace").val();


        $.ajax
        (
            {
                url: "/Test/buyer?method=updateBuyer",//请求路径
                data: { id:id , buyername:buyername, password:password ,buyernum:buyernum ,buyerplace:buyerplace},//请求数据
                type: "post",//请求方式 GET/POST/ PUT/DELETE
                //dataType: "json",//请求数据类型
                //contentType: "application/json",//返回数据类型
                success: function (data) {
                    console.log(data);
                    data = JSON.parse(data);//把后台的数据处理为json格式
                    if (data.code == "0000") {

                        /*OrdersList(1, 5);//刷新列表
                        $("#myModal2").modal("hide");//模态框隐藏*/
                        alert("修改成功！");

                    } else {
                        alert("修改失败！");
                    }
                }
            }
        )
    }

    document.getElementById("btn2").onclick = function()
    {
        location.href="home2.jsp";

    }

</script>
</html>
